package com.fisher.checker.db.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.fisher.checker.db.entity.ProductItemEntity;

import java.util.List;

@Dao
public interface ProductItemDao {
    @Insert
    long insertProductItem(ProductItemEntity productItem);

    @Query("DELETE FROM product_items WHERE itemId = :itemId")
    void deleteProductItem(long itemId);

    @Query("DELETE FROM product_items")
    void clearTable();

    @Query("SELECT * FROM product_items ORDER BY itemId")
    List<ProductItemEntity> getAllProductItems();
    @Query("SELECT * FROM product_items WHERE productNo = :productNo ORDER BY itemId")
    List<ProductItemEntity> getProductItemsByProductNo(String productNo);

    @Query("SELECT EXISTS (SELECT 1 FROM product_items WHERE productBarcode = :barcode LIMIT 1)")
    boolean doesProductExist(String barcode);

    @Query("SELECT EXISTS (SELECT 1 FROM product_items WHERE electronPartBarcode = :barcode LIMIT 1)")
    boolean doesElectronPartExist(String barcode);
}
